<?php

$current_page = get_smarty();

$current_page->assign( 'logged', $User->is_logged() );

$current_page->assign( 'debug', $_SERVER );

switch( $URL[1] )
{
	case '':
	default:
		$_page_content = $current_page->fetch( 'user.tpl' );
		break;
	case 'logout':
		$User->logout();
		$_page_content .= $current_page->fetch( 'home.tpl' );		
		break;
	case 'login':
		$logged = $User->login( $_POST['username'], $_POST['password'], true );
		if ( $logged )
		{
			
		}
		else
		{
			$current_page->assign( 'login_error', $User->ERROR );
		}
		
		$current_page->assign( 'logged', $logged );
		
		$_page_content .= $current_page->fetch( 'user_login.tpl' );
		break;
	case 'register':
		$registered = false;
		
		// We know what's the users time, so we can save for him the difference.
		// Use this to set up the user's default timezone.
		$local_hour = $_POST['localhour'];
		
		// This is the server's difference from GMT time ( Ex: +0300 )
		$server_gmt_difference = date( 'O' );
	
		if ( $User->is_logged() )
		{
			$current_page->assign( 'already_logged', true );
		}
		else
		{
			$registered = $User->new_user( $_POST['username'], $_POST['password'] );
			if ( $registered == 'USER_EXISTS' )
			{
				$current_page->assign( 'registered', 'USER_EXISTS' );
			}
			elseif ( is_int( $registered ) )
			{
				$current_page->assign( 'registered', 'OK' );		
			}
			else
			{
				$current_page->assign( 'registered', 'UNKOWN_ERROR' );
			}
			
		}

		$_page_content .= $current_page->fetch( 'user_register.tpl' );
	
		break;
	case 'logout':
		$User->logout();
		break;
}



?>